package tournamentmanager;

import com.google.inject.Binder;
import com.google.inject.Module;
import gui.TourneyManView;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TourneyManModule implements Module {

  public void configure(Binder binder) {
    TourneyManView tourneyManView = new TourneyManView();
    binder.bind(TourneyManView.class).toInstance(tourneyManView);

    Preferences preferences = getPreferences();
    binder.bind(Preferences.class).toInstance(preferences);
  }

  private Preferences getPreferences() {
    try {
      return (Preferences)Util.readFromFile(Preferences.TOURNEYMAN_PREFERENCES);
    }
    catch (Exception e) {
      Logger.getLogger(getClass().getName()).log(Level.WARNING, "reading file failed", e);
      Preferences preferences;
      preferences = new Preferences();
      preferences.setPreConfEnginesLst(new ArrayList<ChessEngine>());
      preferences.setSimulTournament(new SimulTournament(null));
      preferences.setRoundRobinTournament(new RoundRobinTournament());
      return preferences;
    }
  }

}
